package com.bestow.basic.controller;

import java.util.HashMap;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.bestow.basic.service.IFndCodingRuleValuesService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.bestow.common.annotation.Log;
import com.bestow.common.core.controller.BaseController;
import com.bestow.common.core.domain.AjaxResult;
import com.bestow.common.enums.BusinessType;
import com.bestow.basic.domain.FndCurrency;
import com.bestow.basic.service.IFndCurrencyService;
import com.bestow.common.utils.poi.ExcelUtil;
import com.bestow.common.core.page.TableDataInfo;

/**
 * 币种Controller
 *
 * @author liliu
 * @date 2022-09-02
 */
@RestController
@RequestMapping("/basic/currency")
public class FndCurrencyController extends BaseController {
    @Autowired
    private IFndCurrencyService fndCurrencyService;
    @Autowired
    private IFndCodingRuleValuesService fndCodingRuleValuesService;

    /**
     * 查询币种列表
     */
    @PreAuthorize("@ss.hasPermi('basic:currency:list')")
    @GetMapping("/list")
    public TableDataInfo list(FndCurrency fndCurrency) {
        startPage();
        List<FndCurrency> list = fndCurrencyService.selectFndCurrencyList(fndCurrency);
        return getDataTable(list);
    }

    /**
     * 导出币种列表
     */
    @PreAuthorize("@ss.hasPermi('basic:currency:export')")
    @Log(title = "币种", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FndCurrency fndCurrency) {
        List<FndCurrency> list = fndCurrencyService.selectFndCurrencyList(fndCurrency);
        ExcelUtil<FndCurrency> util = new ExcelUtil<FndCurrency>(FndCurrency.class);
        util.exportExcel(response, list, "币种数据");
    }

    /**
     * 获取币种详细信息
     */
    @PreAuthorize("@ss.hasPermi('basic:currency:query')")
    @GetMapping(value = "/{currencyCode}")
    public AjaxResult getInfo(@PathVariable("currencyCode") String currencyCode) {
        return AjaxResult.success(fndCurrencyService.selectFndCurrencyByCurrencyCode(currencyCode));
    }

    /**
     * 新增币种
     */
    @PreAuthorize("@ss.hasPermi('basic:currency:add')")
    @Log(title = "币种", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FndCurrency fndCurrency) {
        return toAjax(fndCurrencyService.insertFndCurrency(fndCurrency));
    }

    /**
     * 修改币种
     */
    @PreAuthorize("@ss.hasPermi('basic:currency:edit')")
    @Log(title = "币种", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FndCurrency fndCurrency) {
        return toAjax(fndCurrencyService.updateFndCurrency(fndCurrency));
    }

    /**
     * 删除币种
     */
    @PreAuthorize("@ss.hasPermi('basic:currency:remove')")
    @Log(title = "币种", businessType = BusinessType.DELETE)
    @DeleteMapping("/{currencyCodes}")
    public AjaxResult remove(@PathVariable String[] currencyCodes) {
        return toAjax(fndCurrencyService.deleteFndCurrencyByCurrencyCodes(currencyCodes));
    }
}
